package com.boglond.util;

import com.boglond.builder.GenerateXMLInterfaceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseUtil {

    private static final Logger log = LoggerFactory.getLogger(DatabaseUtil.class);


    private DatabaseUtil(){

    }

    private static Connection conn;

    private static final String DRIVER_CLASS = PropertyUtil.getValueByKey("jdbc.driver");

    private static final String CONNECTION_URL = PropertyUtil.getValueByKey("jdbc.url");

    private static final String USERNAME = PropertyUtil.getValueByKey("jdbc.username");

    private static final String PASSWORD = PropertyUtil.getValueByKey("jdbc.password");

    static{
        try {
            Class.forName(DRIVER_CLASS);
            conn = DriverManager.getConnection(CONNECTION_URL, USERNAME, PASSWORD);
        } catch (ClassNotFoundException e) {
            log.error(">> 数据库工具类异常,详细信息:{}",e);
            throw new RuntimeException(e);
        } catch (SQLException e) {
            log.error(">> 数据库工具类异常,详细信息:{}",e);
            throw new RuntimeException(e);
        }
    }


    public static final Connection getConnection(){
        return conn;
    }

    public static final DatabaseMetaData getDatabaseMetaData(){
        try {
            return getConnection().getMetaData();
        } catch (SQLException e) {
            log.error(">> 数据库工具类获取DatabaseMetaData异常,详细信息:{}",e);
        }
        return null;
    }









}
